﻿using NpcFramework.Traffic;
using UnityEngine;

namespace NpcFramework
{
    public class TrafficCarSeeker : NpcSeeker
    {
        public TrafficCar TrafficCar;

        [Range(1,10)]
        public float EndPathDistance = 5f;
        
        public override bool ReachedEndOfPath()
        {
            if (TrafficCar.rayOrigin == null)
            {
                return true;
            }

            float distance = Vector3.Distance(TrafficCar.rayOrigin.transform.position, _destination);
            if (distance < EndPathDistance)
            {
                return true;
            }
            
            return false;
        }
        
        public override void SetDestination(Vector3 destination)
        {
            _destination = destination;
            NFMgr.DataManager.GetNpcData(ID).Destination = destination;
            TrafficCar.SetTargetPos(destination);    
        }


        public void BeginDriving(Vector3 pos)
        {
            gameObject.GetComponent<Rigidbody>().useGravity = true;
            float h = TrafficCar.GetHeight() + 0.02f;
            Transform.position = new Vector3(pos.x,h,pos.z);
        }
    }
}
